home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / dnsconf / primquery.c < prev    next >
C/C++ Source or Header  |  1995-10-15  |  2KB  |  87 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "dnsconf.h"
  5. #include "internal.h"
  6.  
  7. /*
  8.     Replace or add a record in this DOMAIN definition.
  9.     new_rec has been created with new. It will be managed (even deleted)
  10.     by this function.
  11. */
  12. PUBLIC int PRIMARY::set (FQHOST &fq, RECORD *new_rec)
  13. {
  14.     /* #Specification: record file / multiple origin
  15.         dnsconf can update with multiple $ORIGIN statement.
  16.         It will find the closest origin.
  17.     */
  18.     ORIGIN *match_ori = NULL;
  19.     int minlevel = 100;
  20.     for (int i=0; i<origins.getnb(); i++){
  21.         ORIGIN *ori = origins.getitem(i);
  22.         char hostpart[200];
  23.         int level = fq.is_member(ori->origin.get(),hostpart);
  24.         if (level > 0 && level < minlevel){
  25.             match_ori = ori;
  26.             new_rec->sethostpart(hostpart);
  27.             minlevel = level;
  28.         }
  29.     }
  30.     if (match_ori != NULL){
  31.         match_ori->tbrec.add (new_rec);
  32.         updatesoa();
  33.     }
  34.     return 0;
  35. }
  36. /*
  37.     Erase a record in this DOMAIN definition.
  38.     new_rec has been created with new. It is used to find the record
  39.     to delete. It is also deleted by this function.
  40. */
  41. PUBLIC int PRIMARY::unset (RECORD *new_rec)
  42. {
  43.     bool found = false;
  44.     for (int i=0; i<origins.getnb() && !found; i++){
  45.         ORIGIN *ori = origins.getitem(i);
  46.         for (int o=0; o<ori->tbrec.getnb(); o++){
  47.             RECORD *rec = ori->tbrec.getitem(o);
  48.             if (rec->cmp(new_rec) == 0){
  49.                 ori->tbrec.remove_del(rec);
  50.                 o--;
  51.                 found = true;
  52.             }
  53.         }
  54.     }
  55.     if (found) updatesoa();
  56.     delete new_rec;
  57.     return 0;
  58. }
  59.  
  60.  
  61. /*
  62.     Locate all record of a type using the left value has the key.
  63. */
  64. PUBLIC int PRIMARY::locate_left (
  65.     FQHOST &fq,
  66.     RECORD_TYPE rtype,
  67.     RECORDS &recs)
  68. {
  69.     recs.neverdelete();
  70.     for (int i=0; i<origins.getnb(); i++){
  71.         ORIGIN *ori = origins.getitem(i);
  72.         char hostpart[200];
  73.         int level = fq.is_member(ori->origin.get(),hostpart);
  74.         if (level > 0){
  75.             for (int o=0; o<ori->tbrec.getnb(); o++){
  76.                 RECORD *rec = ori->tbrec.getitem(o);
  77.                 if (rec->is (rtype)
  78.                     && rec->cmp_left (hostpart)==0){
  79.                     recs.add (rec);
  80.                 }
  81.             }
  82.         }
  83.     }
  84.     return recs.getnb();
  85. }
  86.  
  87.